<?php
class TableModel extends CommonModel {
    public $_validate = array(
//        array('company_id','require','公司必选'),
//        array('sortname','require','类别必须'),
//        array('abroadname','','外国名已经存在',self::EXISTS_VALIDATE,'unique',self::MODEL_INSERT),
//        array('code','','编码已经存在',self::EXISTS_VALIDATE,'unique',self::MODEL_INSERT),
    );

    public $_auto = array(
        array('create_by', 'getUserId', 1,'callback'),
    );
    
    function getUserId(){
        return $_SESSION[C('USER_AUTH_KEY')];
    }

    protected $_link = array(
        'Company'=> array(
            'mapping_type'=>BELONGS_TO,             
            //'class_name'=>'Classes',             
            //外键       
            'foreign_key'=>'company_id',             
            'mapping_name'=>'company' ,             
            //关联的字段，可以多个             
            'mapping_fields'=>'company_name',             
            'as_fields'=>'company_name:companyname'            
        ),     
        'User'=> array(
            'mapping_type'=>BELONGS_TO,             
            //'class_name'=>'Classes',             
            //外键       
            'foreign_key'=>'create_by',             
            'mapping_name'=>'user' ,             
            //关联的字段，可以多个             
            'mapping_fields'=>'nickname',             
            'as_fields'=>'nickname:nickname'            
        )
    ); 
    
}